import sys

from scripts.BackupRestore import BackupRestore
from scripts.Log import Log
from scripts.util.Util import Util
from scripts.ui.MainWindow import MainWindow


def start_gui():
    Log.d('GUI start')
    MainWindow().show()
    Log.d('GUI closed')
    Util.exit(0)


def main():
    if len(sys.argv) == 1:
        Util.exit_on_exception(start_gui)
    elif len(sys.argv) == 3:
        if len(sys.argv) != 3:
            Log.e('Invalid parameter')
            return

        br = BackupRestore(None, sys.argv[2], [
            BackupRestore.STEP_PREPARE,
            BackupRestore.STEP_BACKUP_APP,
            BackupRestore.STEP_BACKUP_ADB_BACKUP,
            BackupRestore.STEP_BACKUP_APP_DATA,
            BackupRestore.STEP_BACKUP_SYSTEM,
            BackupRestore.STEP_BACKUP_MISC,
            BackupRestore.STEP_CLEANUP
        ])

        if sys.argv[1] == 'backup':
            br.backup()
        elif sys.argv[1] == 'restore':
            br.restore()
        else:
            Log.e('Invalid parameter')


if __name__ == '__main__':
    main()
